Skip to content

fs: fix glob results on Windows for '..' and drive-less roots - #67776

Open
Rio3210 wants to merge 2 commits into
nodejs:mainfrom
Rio3210:fs-glob-windows-roots
Open

Rio3210 wants to merge 2 commits into
nodejs:mainfrom
Rio3210:fs-glob-windows-roots

Conversation

@Rio3210

@Rio3210 Rio3210 commented Nov 25, 2026

Copy link
Copy Markdown

Fixes two Windows regressions introduced by the native glob implementation in #65392. Both also affect v27.0.0-alpha.0.1.1. Node.js v26.x and earlier use the previous JavaScript implementation and are unaffected.

Pattern v26.13.1 main
../sib/**/*.js ..\sib\a.js ../sib\a.js
\Users\<user>\...\sib\*.js (no drive letter) \Users\<user>\...\sib\a.js []
Reproduction
import { mkdirSync, writeFileSync, globSync, realpathSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';

const root = join(realpathSync.native(tmpdir()), 'glob-win-repro');
mkdirSync(join(root, 'cwd'), { recursive: true });
mkdirSync(join(root, 'sib', 'sub'), { recursive: true });
writeFileSync(join(root, 'sib', 'a.js'), '');
writeFileSync(join(root, 'sib', 'sub', 'b.js'), '');

// 1. Pattern starting with '..'.
console.log(globSync('../sib/**/*.js', { cwd: join(root, 'cwd') }));

// 2. Absolute pattern without a drive letter.
console.log(globSync(join(root, 'sib', '*.js').slice(2)));

Drive-less absolute patterns: Looking up a literal segment after the root \ called Join("\\", "Users"), producing \\Users. Normalize() preserved the leading backslashes as a UNC prefix, causing the lookup to fail and the glob to return no matches. Join() now avoids adding a separator when the first part already ends with one, matching path.win32.join() for this case. The root is also queued with the platform separator so returned paths do not start with /.

Mixed separators in .. results: The parent directory was queued as the hardcoded string '../'. Because JoinEntry() appends child names directly after a trailing separator, the forward slash remained in returned paths. The parent directory now uses the platform separator.

The previous JavaScript implementation used the same '/' and '../' strings, but normalized child paths through path.join(). POSIX behavior is unchanged: the queued strings remain the same, and Normalize() already collapses the extra separator added by Join().

Tests

  • Add Windows-only test/parallel/test-fs-glob-windows-no-drive-letter.mjs, covering drive-less patterns with backslashes, forward slashes, and a literal path across the callback, synchronous, and promises APIs.
  • Add '../abs/*' and the literal control '../abs/foo' to the shared patterns table in test/parallel/test-fs-glob.mjs. The existing harness exercises both through all three APIs, including file: URL cwd, withFileTypes, and exclude.

Verification

Both bugs were reproduced on Windows 11 with v28.0.0-nightly20261124d2c9ac02cb. The new tests fail on that nightly and pass on v26.13.1, which returns the expected results.

On Ubuntu 22.04, the same nightly passes the full test-fs-glob.mjs suite, including the new .. cases. The Windows-only test skips as expected.

I have not built Node.js locally, so build and runtime verification of the fix remains for CI. Local checks included:

  • Compile-checking glob_walker.cc against the Node.js headers with clang-cl 19.
  • Comparing Join() before and after the change against path.win32.join() and path.posix.join(). In the cases checked, only drive-less root results changed; they now match path.win32.join(). POSIX results were unchanged.

Refs: #65392

On Windows, an absolute glob pattern without a drive letter, such as
'\Users\me\*.js' or '/Users/me/*.js', returned no results as soon as a
literal segment followed the root. The walker looks up a literal child
with Join(fullpath, name). For the drive-less root '\' that built
'\\Users', which Normalize() keeps as a UNC prefix, so the lookup
failed. path.win32.join() returns '\Users' here.

Skip the separator in Join() when the first part already ends with
one. Also queue the root with the platform separator: JoinEntry()
appends child names right after it, so a '/' leaked into results
('/Users\me').

Signed-off-by: Surafel Workayehu <surafelwork32@gmail.com>
On Windows, a glob pattern starting with '..' returned paths such as
'../sib\a.js'. The walker queued the parent directory as '../', and
JoinEntry() appends child names right after a trailing separator, so
the '/' stayed in every result. The previous JS implementation built
child paths with path.join(), which normalized it.

Use the platform separator, as for the drive-less root. POSIX output
is unchanged.

Signed-off-by: Surafel Workayehu <surafelwork32@gmail.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants